package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.QuestionMapper;
import com.tanhua.model.domain.Question;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author wjs
 * @version 1.0
 * @date 2021/12/24 0024 下午 4:22
 */

@DubboService
public class QuestionApiImpl implements QuestionApi{
    @Autowired
    private QuestionMapper questionMapper;

    /**
     * 通过userId查询
     * @param userId
     * @return
     */
    @Override
    public Question findByUserId(Long userId) {
        LambdaQueryWrapper<Question> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Question::getUserId,userId);

        Question question = questionMapper.selectOne(lqw);
//        QueryWrapper<Question> qw = new QueryWrapper<>();
//        qw.eq("user_id",userId);
//        Question question = questionMapper.selectOne(qw);

        return question;
    }

    /**
     * 保存Question
     * @param question
     */
    @Override
    public void saveQuestions(Question question) {
        questionMapper.insert(question);
    }

    /**
     * 更新Question
     * @param question
     */
    @Override
    public void updateQuestions(Question question) {
        questionMapper.updateById(question);
    }
}
